import 'dart:async';

import 'package:flutter/widgets.dart';

/// 控制器
class BaseSearchBarController extends ChangeNotifier {
  String searchKey;
  final StreamController<BaseSearchBarConfigModel> streamController;
  BaseSearchBarController({@required this.streamController, this.searchKey});

  void changeSearchKey(String searchKey) {
    this.searchKey = searchKey;
    notifyListeners();
  }

  /// 创建
  void changeConfig(BaseSearchBarConfigModel config) {
    this.streamController.sink.add(config);
  }

  /// 创建
  void buildExpansion(Widget expansion) {
    BaseSearchBarConfigModel _config = BaseSearchBarConfigModel(expansion: expansion);
    this.streamController.sink.add(_config);
  }

  /// 改变提示语
  void changeHitText(String text) {
    BaseSearchBarConfigModel _config = BaseSearchBarConfigModel(hitText: text);
    this.streamController.sink.add(_config);
  }

  void hideSearchBar(bool bool) {
    BaseSearchBarConfigModel _config = BaseSearchBarConfigModel(hideSearchBar: bool);
    this.streamController.sink.add(_config);
  }
}

/// 控制器流模型
class BaseSearchBarConfigModel {
  final bool hideSearchBar;
  final String hitText;
  final Widget expansion;
  BaseSearchBarConfigModel({this.hideSearchBar, this.hitText, this.expansion});
}
